//
// Created by bleedingfight on 2020/6/25.
//
#include "isValid.h"

bool isValid(std::string s){
    int num;
    std::stack<int> symb;
    std::map<char,int> sym_map;
    sym_map['('] = -1;
    sym_map[')'] = 1;
    sym_map['{'] = -2;
    sym_map['}'] = 2;
    sym_map['['] = -3;
    sym_map[']'] = 3;
    for(int i=0;i<s.size();i++){
        if(symb.empty()){
            symb.push(sym_map[s.at(i)]);
        }
        else{
            num = symb.top();
            int current_int = sym_map[s.at(i)];
            if((num+current_int)==0){
                symb.pop();
            } else
                symb.push(current_int);
        }

    }
    if(symb.empty())
        return true;
    else
        return false;
}

